#include<iostream>
#include<queue>
using namespace std;
typedef long long LL;
int n;
queue<LL>q;
const int N = 1e3 + 10;
void bfs()
{
	LL q[N * N] = { 0 };
	int tt = 0, hh = 0;
	q[0] = 1;
	while (hh <= tt) {
		LL t = q[hh++];
		if (t % n == 0) {
			cout << t << endl;
			return;
		}
		q[++tt] = t * 10;
		q[++tt] = t * 10 + 1;
	}
}
int main()
{
	while (cin >> n, n) {
		while (q.size()) {
			q.pop();
		}
		q.push(1);
		while (q.size()) {
			LL t = q.front();
			q.pop();
			if (t % n == 0) {
				cout << t << endl;
				break;
			}
			q.push(t * 10);
			q.push(t * 10 + 1);
		}
	}
	return 0;
}